<?php
require_once("../../config.inc.php");
require_once(SERVER_FS_ROOT."/app/_inc/mix.func.php");
require_once(SERVER_FS_ROOT."/app/_inc/mbUser.class.php");
require_once(SERVER_FS_ROOT."/app/_inc/sdao/StructuredDataAccessObject.php");

if (!isset($_REQUEST['xsn'])) {
	serverRedir(SERVER_URL_ROOT."/app/_com/login.php?errMsg=9997");
	exit();
}
session_start();
$ax = explode('.',$_REQUEST['xsn']);
$subSess = $ax[0];
if (!isset($isPopUp)) $isPopUp = false;
if (!isset($isReloadable)) $isReloadable = true;
if (!isset($ax[1])) {
	if (!$isPopUp) {
		serverRedir(SERVER_URL_ROOT."/app/_com/login.php?errMsg=9997");
		exit();
	}
	$pageSeq = 0;
} else {
	$pageSeq = intval($ax[1]);
}
$userObjKey = 'polarismb'.$subSess;
if(!isset($_SESSION[$userObjKey])){
	serverRedir(SERVER_URL_ROOT."/app/_com/login.php?errMsg=9998");
	exit();
}
if($_SESSION[$userObjKey]->user == '@@logout@@'){
	serverRedir(SERVER_URL_ROOT."/app/_com/login.php?errMsg=9996");
	exit();
}
if (!isset($objSDAO)) $objSDAO = new SDAO($aMetaConPar);
$subSess=1;
while(isset($_SESSION['polarismb'.$subSess])) {$subSess++;}
$_SESSION['polarismb'.$subSess] = clone $_SESSION[$userObjKey];
$oUser = $_SESSION['polarismb'.$subSess];
$oUser->uniqid = md5(uniqid(rand(), true));
list($usec, $sec) = explode(" ", microtime());
$tsNow = date('Y-m-d H:i:s',$sec).substr($usec,1,7); 
$sSQL = "INSERT INTO session " .
		"(uniqid, time_in, id_user, session_id, sub_session, time_last, log_out) " .
		"VALUES('".$oUser->uniqid."', TIMESTAMP('$tsNow'), ".$oUser->id.", '".session_id()."', $subSess, TIMESTAMP('$tsNow'),'N')";	
$bRC = $objSDAO->query($sSQL,"insSess",array("contOnErr"=>true));
define('USEROBJ','polarismb'.$subSess);
define('XSN',"$subSess.".$oUser->pageSequence);
define('SUB_SESSION_NUMBER',$subSess);
header("location: ".$oUser->getHistory(0,true));
exit();
?>
